package com.gongpingjialoan.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.gongpingjialoan.R;

public class PhoneDialog extends Dialog{

    private PhoneDialog mySelf = this;
    Context context;
    private Handler messageHanlder;
    private Button yes_layout;
    private Button no_layout;
    private TextView title_txt;
    private String title;
    private String confirmTitle;
    
    
    public PhoneDialog(Context context,String title,Handler messageHanlder) {
        super(context,R.style.dialogs);
        this.context = context;
        this.messageHanlder = messageHanlder;
        this.title = title;
    }


    public void setConfirmTitle(String title){
        this.confirmTitle = title;
    }

    
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.phone_dialog);
        this.setCanceledOnTouchOutside(false);
        yes_layout = (Button)this.findViewById(R.id.yes_btn);
        if(!TextUtils.isEmpty(confirmTitle)){
            yes_layout.setText(confirmTitle);
        }
        no_layout = (Button)this.findViewById(R.id.no_btn);
        title_txt = (TextView)this.findViewById(R.id.phone_number);
        title_txt.setText(title);
        yes_layout.setOnClickListener(new android.view.View.OnClickListener() {
            public void onClick(View v) {
                if (messageHanlder != null) {
                    Message msg = new Message();
                    msg.what = 1;
                    messageHanlder.sendMessage(msg);
                }
                mySelf.dismiss();
            }
        });
        no_layout.setOnClickListener(new android.view.View.OnClickListener() {
            public void onClick(View v) {
                if (messageHanlder != null) {
                    Message msg = new Message();
                    msg.what = 2;
                    messageHanlder.sendMessage(msg);
                }
                mySelf.dismiss();
            }
        });
        mySelf.setCanceledOnTouchOutside(true);
    }

}
